<?php
session_save_path('sessions');
session_start();

// Include our DB user types for proper routing
include("include/dbUserTypes.php");

// Include our user class
include_once("include/user.php");


// Create a variable to store our user if we're validated
$user = null;

// Check if the user session is not set or if it is set but is null
// If either of the above is the case, then go back to the main login page
// Else route to the appropriate page
if( !isset($_SESSION['user']) || $_SESSION['user'] == null ) {
    header("location:main_login.php");
}
else {
    // Unserialize our user to turn it back into a useful object
    $user = unserialize($_SESSION['user']);
    
    // Reroute the user to the proper homepage
    switch($user->getUserType()) {
        case $USERTYPE_ADMIN:
            header("location:admin_index.php");
            break;
        case $USERTYPE_BUSINESS:
            header("location:business_index.php");
            break;
        case $USERTYPE_FINANCIAL:
            header("location:financial_index.php");
            break;
        case $USERTYPE_REGISTERED:
            header("location:registered_index.php");
            break;
        default:
            header("location: index.php");
    }
}
?>